home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / mcomm600.zip / WATCHDOG.C < prev    next >
C/C++ Source or Header  |  1994-10-03  |  3KB  |  71 lines

  1.  
  2. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. *                                                                           *
  4. *             W A T C H D O G   F U N C T I O N   F O R   M S C             *
  5. *               Mike Dumdei, 6 Holly Lane, Texarkana TX 75503               *
  6. *                    Requires ASM module --> WDOGHOOK.ASM                   *
  7. *                                                                           *
  8. *       IF YOU USE THE TICKHOOK FUNCTION IN COMMx.LIB AND THIS FUNC-        *
  9. *       TION IN THE SAME PROGRAM YOU MUST UNINSTALL THE HOOKS IN THE        *
  10. *       REVERSE ORDER THAT THEY WERE INSTALLED  !!!!!!!!!!!!                *
  11. *       -------------------------------------------------------------       *
  12. *                                                                           *
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  14. #if defined (__TURBOC__)
  15.   #define DosGetVect  getvect
  16.   #define DosSetVect  setvect
  17. #else
  18.   #define DosGetVect _dos_getvect
  19.   #define DosSetVect _dos_setvect
  20. #endif
  21.  
  22. #if defined(__ZTC__)
  23.   #include <int.h>
  24.   #define INTERRUPT
  25. #else
  26.   #include <dos.h>
  27.   #define INTERRUPT interrupt
  28. #endif
  29.  
  30. #define uint    unsigned int
  31. #define TIMER   0x1C                        /* timer tick interrupt vector */
  32.  
  33. /* these are in the ASM module */
  34. void INTERRUPT far watchdoghook(void);
  35. extern void (INTERRUPT far *oldtimerint)();
  36. extern uint msrportadrs;
  37.  
  38. int watchdogset(int flag, uint combase)
  39. {
  40.     if (flag)                                         /* enabling watchdog */
  41.     {
  42.         if (msrportadrs != 0)
  43.             return (-1);                       /* error if already enabled */
  44.         /* else set pointers and hook into the timer interrupt */
  45.         msrportadrs = combase + 6;       /* point to modem status register */
  46. #if !defined (__ZTC__)
  47.         oldtimerint = DosGetVect(TIMER);
  48.         DosSetVect(TIMER, watchdoghook);                 /* hook the timer */
  49. #else
  50.         int_getvector(TIMER, (uint *)&oldtimerint, (uint *)(&oldtimerint+2));
  51.         int_setvector(TIMER, (uint)watchdoghook, *(uint *)(&watchdoghook+2));
  52. #endif
  53.         return (0);
  54.     }
  55.     else                                             /* disabling watchdog */
  56.     {
  57.         if (msrportadrs == 0)
  58.             return (-1);                           /* error if not enabled */
  59.         /* else set timer back to original vector & reset comchip var */
  60. #if !defined (__ZTC__)
  61.         DosSetVect(TIMER, oldtimerint);        /* reset vector to original */
  62. #else
  63.         int_setvector(TIMER, (uint)oldtimerint, *(uint *)(&oldtimerint+2));
  64. #endif
  65.         msrportadrs = 0;
  66.         return (0);
  67.     }
  68. }
  69.  
  70.         
  71.